﻿cmake_minimum_required(VERSION 3.14)

project(Test0 LANGUAGES CXX CUDA)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 使用 OpenCV
find_package(OpenCV REQUIRED)

# CUDA
find_package(CUDAToolkit REQUIRED)
add_definitions(-DUSE_CUDA)

# 设置 ONNXRUNTIME_VERSION 版本号
set(ONNXRUNTIME_VERSION 1.17.0)
set(ONNXRUNTIME_ROOT "D:/CodeSofts/DeepLearning/ONNX/onnxruntime-win-x64-gpu-${ONNXRUNTIME_VERSION}")
#set(ONNXRUNTIME_ROOT "D:/CodeSofts/DeepLearning/ONNX/onnxruntime-win-x64-${ONNXRUNTIME_VERSION}")
include_directories(${PROJECT_NAME} ${ONNXRUNTIME_ROOT}/include)
link_directories(${ONNXRUNTIME_ROOT}/lib)

file(GLOB SourceFiles ${SourceFileTypes})
add_executable(${PROJECT_NAME}
        ${SourceFiles}
)


INSTALL(TARGETS ${PROJECT_NAME}
        RUNTIME DESTINATION bin
        ARCHIVE DESTINATION lib
)

target_link_libraries(${PROJECT_NAME}
        PRIVATE
        ${OpenCV_LIBS}
        CUDA::cudart
        onnxruntime
)

#set_target_properties(${PROJECT_NAME} PROPERTIES
#        CUDA_SEPARABLE_COMPILATION ON)

# 将onnx的dll文件复制到目标目录
if (WIN32)
    file(GLOB ONNX_DLLS "${ONNXRUNTIME_ROOT}/lib/*.dll")
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${ONNX_DLLS}
            $<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif ()
